package cn.wolfcode.wolf2w.elasticsearch.service.impl;

import cn.wolfcode.wolf2w.elasticsearch.domain.UserInfoEs;
import cn.wolfcode.wolf2w.elasticsearch.repository.UserInfoESRepository;
import cn.wolfcode.wolf2w.elasticsearch.service.IUserInfoESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserInfoESServiceImpl implements IUserInfoESService {
    @Autowired
    private UserInfoESRepository userInfoERepository;

    @Autowired
    private ElasticsearchTemplate template;

    @Override
    public void save(UserInfoEs userInfoE) {
        userInfoERepository.save(userInfoE);
    }

    @Override
    public void update(UserInfoEs userInfoE) {
        userInfoERepository.save(userInfoE);
    }

    @Override
    public void delete(String id) {
        userInfoERepository.deleteById(id);
    }

    @Override
    public UserInfoEs get(String id) {
        return userInfoERepository.findById(id).orElse(null);
    }

    @Override
    public List<UserInfoEs> listAll() {
        Iterable<UserInfoEs> iterable = userInfoERepository.findAll();
        ArrayList<UserInfoEs> list = new ArrayList<>();
        iterable.forEach(a -> list.add(a));
        return list;
    }
}